<!DOCTYPE html>
<html lang="zh-CN">
  	<head>
    	<meta charset="utf-8">
    	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="width=device-width, initial-scale=1">
    	<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    	<title>CW360Tech ICD Annotation</title>

    	<!-- Bootstrap -->
    	<link rel="stylesheet" href="lib/bootstrap-3.3.7/css/bootstrap.min.css"  />
  	</head>
  	<body>
	  	 <div class="container-fluid" id="tabLayouts" style="margin-top: 10px;">
			
            <div class="row" style="margin-top: 10px;">
                <div class="col-sm-4">
                   <textarea id="text" placeholder="请输入内容" style="height:100%;width:100%;" rows=30></textarea>
                    <div class="row" style="text-align:center;">
				<div class="col-sm-12">
				<!-- 提供额外的视觉效果，标识一组按钮中的原始动作 -->
				<button type="button" onclick="test()" class="btn btn-primary">解析</button>
				</div>
			</div>
                </div>
                <div class="col-sm-8" id="context">
                    <div class="panel panel-default">
						<div class="panel-heading">
							<h3 id="title" class="panel-title">
								Sign 病症
							</h3>
						</div>
						<div style="overflow:auto;"  class="panel-body">
							<div id="signInfo" class="panel-body">
								
							</div>
						</div>
					</div>
					<div class="panel panel-default">
						<div class="panel-heading">
							<h3 id="diseaseTitle" class="panel-title">
								Disease 疾病
							</h3>
						</div>
						<div style="overflow:auto;"  class="panel-body">
							<div id="disease">
								
							</div>
						<div>
					</div>
                </div>
            </div>

        </div>

    	<script src="lib/jquery.min.js"></script>
		<script>
		    $(function(){
			   $("#context").hide();
			   var height = ($(document).height()-50-100*2)/2;
			   $("#signInfo").parent().height(height);
			    $("#disease").parent().height(height);
			});
			function test(){
				$("#context").show();
				$("#signInfo").children().remove();
				$("#disease").children().remove();
				var data = {
					text:$("#text").val()
				};
				jQuery.ajax({
					type: "POST",
					url: "http://192.168.8.109:8889/icdinfo",
					data: JSON.stringify(data),
					contentType: "application/json; charset=utf-8",
					dataType: 'json',
					async: true,
					success: function (resultData) {
						analysisData(resultData.result);						
					},
					error: function (request, textStatus, errorThrown) {
						
					}
				});
				//analysisData(data);			
			}
			
			function analysisData(data){				
				if(data.signs){
					$("#title").html("Sign 病症 ("+data.signs.length+")");
					var signName = "sign_origin_name";
					var signProp = "sign_icd_detail";
					var std_sign = "std_sign";
					var icd_cod_11 = "icd_cod_11";
					$(data.signs).each(function(index,elem){
						 $("#signInfo").append($("<div style='font-size: 22px;'>"+elem[signName]+"</div>"));
						 $("#signInfo").append($('<hr style="border:1 dashed #987cb9;margin-top: 10px;margin-bottom: 10px;" width="100%" color="#987cb9" size=1>'));
						 var signInfo = $('<div class="row" style="margin-top: 10px;"></div>');
						 $("#signInfo").append(signInfo);
						 if(elem[signProp]){
							$(elem[signProp]).each(function(indexS,info){
								var signType = $('<div class="col-sm-6"><div>');
								var icd11Info = $('<div class="col-sm-6"><div>');
								signType.html("标准病症：" + info[std_sign]);
								var icd11text = "ICD11：";
								if(info[icd_cod_11]){
									$(info[icd_cod_11]).each(function(indexI,code){
										icd11text+="["+code+"]";
									});
								}
								icd11Info.html(icd11text);
								signInfo.append(signType);
								signInfo.append(icd11Info);
							 });
						 }
						 $("#signInfo").append($('<hr style="border:1 dashed #987cb9;margin-top: 10px;margin-bottom: 10px;" width="100%" color="#987cb9" size=1>'));
					});
					var disease_icd_detail = "disease_icd_detail";
					$("#diseaseTitle").html("Disease 疾病 ("+data.diseases.length+")");
					$(data.diseases).each(function(index,elem){
						 $("#disease").append($("<div style='font-size: 22px;'>"+elem["disease_origin_name"]+"</div>"));
						 $("#disease").append($('<hr style="border:1 dashed #987cb9;margin-top: 10px;margin-bottom: 10px;" width="100%" color="#987cb9" size=1>'));
						 var signInfo = $('<div class="row" style="margin-top: 10px;"></div>');
						 $("#disease").append(signInfo);
						 if(elem[disease_icd_detail]){
							$(elem[disease_icd_detail]).each(function(indexS,info){
								var signType = $('<div class="col-sm-6"><div>');
								var icd11Info = $('<div class="col-sm-6"><div>');
								signType.html("标准病症：" + info["std_disease"]);
								var icd11text = "ICD11：";
								if(info[icd_cod_11]){
									$(info[icd_cod_11]).each(function(indexI,code){
										icd11text+="["+code+"]";
									});
								}
								icd11Info.html(icd11text);
								signInfo.append(signType);
								signInfo.append(icd11Info);
							 });
						 }
						 $("#disease").append($('<hr style="border:1 dashed #987cb9;margin-top: 10px;margin-bottom: 10px;" width="100%" color="#987cb9" size=1>'));
					});
				}
			}
		</script>
  	</body>
</html>